#!/user/bin/env python
# -*- coding:utf-8 -*-
# class Wash:
#     def __init__(self, water=10, socur=3):
#         self.water = water
#         self.socur = socur
#
#     def set_water(self, water):
#         self.water = water
#
#     def set_socur(self, socur):
#         self.socur = socur
#
#     def __add_water(self):
#         print("添加水:" + str(self.water))
#
#     def __add_sour(self):
#         print("添加洗衣粉:" + str(self.socur))
#
#     def start_wash(self):
#         self.__add_water()
#         self.__add_sour()
#         print("开始洗衣")
#
#
# if __name__ == '__main__':
#     wash = Wash()
#     # wash.set_water(10)
#     # wash.set_socur(100)
#     wash.start_wash()
#     print "\n"
#
#     wh = Wash(100, 200)
#     wh.start_wash()



# 类的属性,特殊的方法(反射)
# class A:
#     a = 10
#     def __init__(self):
#         self.a =  0
#         self.b = 11
# a = A()
# print  getattr(a,'a')
# setattr(a,'b',12)
# print  getattr(a,'b')
# print  hasattr(a,'cc')


# 属性包装
# class Wash:
#     def __init__(self, water=10, sour=2):
#         self._water = water
#         self.sour = sour
#         self._year = 2010
#
#     @property
#     def water(self):
#         return self._water
#
#     @water.setter
#     def water(self, water):
#         if 0 <= water <= 500:
#             self._water = water
#         else:
#             print "设置失败"
#
#     @property
#     def total_year(self):
#         return self._year - 10
#
#
#     # def set_water(self, water):
#     #     self.water = water
#     #
#     # def set_socur(self, socur):
#     #     self.socur = socur
#
#     def __add_water(self):
#         print("添加水:" + str(self.water))
#
#     def __add_sour(self):
#         print("添加洗衣粉:" + str(self.socur))
#
#     def start_wash(self):
#         self.__add_water()
#         self.__add_sour()
#         print("开始洗衣")
#
#
# if __name__ == "__main__":
#     w = Wash()
#     print  w.water
#
#     w.water = 10000
#     print w.water
#
#     print w.total_year

# 描述符
# 协议方法:__get__(),__set__(),__delete__()

# class NonNeg:
#     def __init__(self, default=0):
#         self.default = default
#
#     def __get__(self, instance, owner):
#         return self.default
#
#     def __set__(self, instance, value):
#         if (value > 0):
#             self.default = value
#         else:
#             print("the value must be native")
#
#     def __delete__(self, instance):
#         pass
#
#
# class Movie:
#     rating = NonNeg()
#     socre = NonNeg()
#
#
# if __name__ == '__main__':
#     m = Movie()
#     print("rating:" + str(m.rating))
#     print("socre:" + str(m.socre))
#     m.rating = 80
#     print("rating:", m.rating)
#     m.socre = -3
#     print("socre:", m.socre)
#
#     print(dir(m))

# 类方法和静态方法
# class DemoClass:
#     def __init__(self, water=2, sour=2):
#         self._water = water
#         self.sour = sour
#         self.year = 2020
#
#     #实例静态方法
#     @staticmethod
#     def spins_ml(spins):
#         return spins * 4
#     #实例静态类
#     @classmethod
#     def get_water(cls, water, sour):
#         return cls(water, cls.spins_ml(10))
#
#     def __add__water(self):
#         print('加水:' + str(self._water))
#
#     def __add_sour(self):
#         print('洗衣粉:' + str(self.sour))
#
#     def start_wash(self):
#         self.__add__water()
#         self.__add_sour()
#         print("开始")
#
#
# if __name__ == "__main__":
#     # num = DemoClass.spins_ml(10)
#     # print(num)
#
#     # w = DemoClass()
#     # print(w.spins_ml(10))
#
#     w = DemoClass.get_water(100, 10)
#     w.start_wash()


# 类的继承与方法的重载
# class A:
#     _company = "zhangsan"
#
#     def __init__(self, ):
#         pass
#
#     def foo(self):
#         print("A foo")
#
# class B:
#     def __init__(self, ):
#         pass
#
#     def foo(self):
#         print("B foo")
#
# class C(A, B):
#     pass
#
# if __name__ == "__main__":
#     c = C()
#     c.foo()


# print(A.__base__)
# print(B.__base__)
# a = A()
# print(a.__company)  # print(A.__company)
# print(D.__bases__)


# 类的特殊方法
# class Empty:
#     def __init__(self):
#         print("test1231")
#
#
# if __name__ == "__main__":
#     Test = Empty
#     Test.foo = "zhangsan"
#
#
#     # print(Test.foo)
#
#     def use_class(mc):
#         return mc()
#
#     # print(use_class(Test))
#     print(type(Empty))